package com.campus.counseling.controller;

import com.campus.counseling.entity.PlatformAccount;
import com.campus.counseling.model.common.Result;
import com.campus.counseling.service.PlatformAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;

@Api(tags = "平台账户管理")
@RestController
@RequestMapping("api/platform/account")
@RequiredArgsConstructor
public class PlatformAccountController {

    private final PlatformAccountService platformAccountService;

    @ApiOperation("获取平台账户信息")
    @GetMapping("/info")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<PlatformAccount> getAccount() {
        return Result.success(platformAccountService.getAccount());
    }

    @ApiOperation("设置平台费率")
    @PutMapping("/fee-rate")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Void> updateFeeRate(@RequestParam BigDecimal feeRate) {
        platformAccountService.updateFeeRate(feeRate);
        return Result.success();
    }

    @ApiOperation("获取平台收入统计")
    @GetMapping("/income/stats")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Object> getIncomeStats(@RequestParam String timeRange) {
        return Result.success(platformAccountService.getIncomeStats(timeRange));
    }

    @ApiOperation("获取平台支出统计")
    @GetMapping("/expense/stats")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Object> getExpenseStats(@RequestParam String timeRange) {
        return Result.success(platformAccountService.getExpenseStats(timeRange));
    }

    @ApiOperation("获取平台资金流水")
    @GetMapping("/flow")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Object> getAccountFlow(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String flowType) {
        return Result.success(platformAccountService.getAccountFlow(pageNum, pageSize, flowType));
    }
} 